home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mfs055 / minixfs.h < prev    next >
C/C++ Source or Header  |  1992-04-12  |  11KB  |  285 lines

  1. #ifndef minixfs_h
  2. #define minixfs_h
  3.  
  4. #define SIZEOF sizeof
  5.  
  6. /* General types we will use */
  7. typedef unsigned short unshort;
  8. typedef unsigned short ushort;
  9. typedef unshort mino_t;
  10. typedef unshort  muid_t;
  11. typedef unsigned char mgid_t;
  12. typedef unsigned char nlink_t;
  13. typedef unshort mode_t;
  14. typedef unshort zone_nr;
  15.  
  16.  
  17. /* User settable parameters */
  18. /*#define MFS_NMOVE_DIR*/    /* no movement of directories (rename OK) */
  19. /*#define LRDEBUG*/        /* debug lrecno */
  20. /*#define BIGDIRTEST*/        /* debug big dir code */
  21. #define SCACHE_SIZE    20    /* # blocks in built in system cache */
  22. #define UCACHE_SIZE    20    /* # blocks in built in user cache */ 
  23. #define NUM_MINIX    10     /* absolute maximum # of minix partitions */
  24. #define WRITETHRU        /* write thru mode */
  25. #define ROBUST            /* Sync periodically on write */
  26.  
  27. #define MAX_INCREMENT    2    /* Determines max filename length,see below */
  28.  
  29. /* Constants for fscntl */
  30.  
  31. #define MFS_BASE    0x100
  32. #define MFS_VERIFY    (MFS_BASE)    /* Return minixfs magic number */
  33. #define MFS_SYNC    (MFS_BASE|0x01)    /* Sync the filesystem */
  34. #define MFS_CINVALID    (MFS_BASE|0x02)    /* Invalidate cache entries */
  35. #define MFS_FINVALID    (MFS_BASE|0x03)    /* Invalidate Fileptrs */
  36. #define MFS_INFO    (MFS_BASE|0x04)    /* Get info about filesystem */
  37. #define MFS_USAGE    (MFS_BASE|0x05)    /* Get block allocation of a file */
  38. #define MFS_IMODE    (MFS_BASE|0x06)    /* Change all bits in an inode mode */
  39. #define MFS_GTRANS    (MFS_BASE|0x07) /* Get filename translation mode */ 
  40. #define MFS_STRANS    (MFS_BASE|0x08) /* Set filename translation mode */
  41.  
  42. #define MFS_MAGIC    0x18970431    /* Magic number from MFS_VERIFY */
  43.  
  44. /* Filename translation modes */
  45.  
  46. #define SRCH_TOS    0x01        /* search with tosify , tos domain  */
  47. #define SRCH_MNT    0x02        /* search with tosify , mint domain */
  48. #define DIR_TOS        0x04        /* dir compat tosify  , tos domain  */
  49. #define DIR_MNT        0x08        /* dir compat tosify  , mint domain */
  50. #define LWR_TOS        0x10        /* lower case creat   , tos domain  */
  51. #define LWR_MNT        0x20        /* lower case creat   , mint domain */
  52. #define AEXEC_TOS    0x40        /* auto 'x' ,   tos domain.   */
  53. #define AEXEC_MNT    0x80        /* auto 'x' ,    mint domain. */
  54.  
  55. /* Default translation modes ... change if desired */
  56. #define TRANS_DEFAULT    (SRCH_TOS | DIR_TOS | DIR_MNT | LWR_TOS | AEXEC_TOS )
  57.  
  58. typedef struct {
  59. long total_inodes,total_zones;
  60. long free_inodes,free_zones;
  61. int version;            /* Filesystem version 1=V1 2=V2 */
  62. int increment;            /* Directory increment */
  63. long res1,res2,res3,res4;    /* Reserved for future use */
  64. } mfs_info;
  65.  
  66.  
  67. /* Macro to determine maximum filename length for a given increment */
  68.  
  69. #define MMAX_FNAME(x) ( ( (x)<<4 ) -2)
  70.  
  71. /* Absolute maximum filename length */
  72.  
  73. #define MNAME_MAX MMAX_FNAME(MAX_INCREMENT)
  74.  
  75. /* Set this to be true if 'c' is an illegal character for a filename */
  76.  
  77. #define BADCHR(c)    (c=='/')
  78.  
  79. /* Some unixes have something a bit stricter,uncomment out this if required */
  80.  
  81. /* #define BADCHR(c) ( (c=='/') || (c & 0x80) ) */
  82.  
  83. /* (or supply your own ) */
  84.  
  85. #define SYMLINK_NAME_MAX 127    /* Maximum size of symlink name */
  86. #define MINIX_MAX_LINK    127    /* Max links to an inode *MUST* be < 256 */
  87. #define BLOCK_SIZE    1024    /* # bytes in a disk block */
  88.  
  89. #define MAJOR             8    /* major device = (dev>>MAJOR) & 0377 */
  90. #define MINOR             0    /* minor device = (dev>>MINOR) & 0377 */
  91. #define NOLAST    (mino_t *) 0    /* We dont want parent directory of a file */
  92.  
  93. /* Flag bits for i_mode in the inode. */
  94.  
  95. #define I_SYMLINK    0160000 /* symbolic link (not standard minix) */
  96.  
  97. #define I_TYPE        0170000    /* this field gives inode type */
  98. #define I_REGULAR    0100000    /* regular file, not dir or special */
  99. #define I_BLOCK_SPECIAL 0060000    /* block special file */
  100. #define I_DIRECTORY    0040000    /* file is a directory */
  101. #define I_CHAR_SPECIAL    0020000    /* character special file */
  102. #define I_NAMED_PIPE    0010000 /* named pipe (FIFO) */
  103. #define I_SET_UID_BIT    0004000    /* set effective uid_t on exec */
  104. #define I_SET_GID_BIT    0002000    /* set effective gid_t on exec */
  105. #define I_STICKY    0001000 /* sticky bit */
  106. #define ALL_MODES    0007777    /* all bits for user, group and others */
  107. #define RWX_MODES    0000777    /* mode bits for RWX only */
  108. #define R_BIT        0000004    /* Rwx protection bit */
  109. #define W_BIT        0000002    /* rWx protection bit */
  110. #define X_BIT        0000001    /* rwX protection bit */
  111. #define I_NOT_ALLOC    0000000    /* this inode is free */
  112.  
  113. /* Useful macros */
  114. #define IS_DIR(m)    ((m.i_mode & I_TYPE)==I_DIRECTORY)
  115. #define IS_REG(m)    ((m.i_mode & I_TYPE)==I_REGULAR)
  116.  
  117. /* Flag bits for cookie 'aux' field */
  118. #define AUX_DEL     1    /* file marked for deletion */
  119. #define AUX_SYNC 2    /* l_sync() on next write */
  120.  
  121. /* Tables sizes */
  122. #define NR_ZONE_NUMS       9    /* # zone numbers in an inode */
  123. #define NR_ZONE_NUMS2      10    /* #zone numbers in v2 inode */
  124.  
  125. /* Miscellaneous constants */
  126. #define SUPER_MAGIC   0x137F    /* magic number contained in super-block */
  127. #define SUPER_V2      0x2468    /* v2 magic number */
  128.  
  129. #define FIND        0    /* tells search_dir to search for file */
  130. #define ADD        1    /* tells search_dir to add a dir entry */
  131. #define KILL        2    /* tells search_dir to kill entry     */
  132. #define POS        3    /* tells search_dir to find position   */
  133.  
  134. #define INVALID        0    /* Cache entry is garbage */
  135. #define CLEAN           1    /* Cache entry same as disk */
  136. #define DIRTY           2    /* Cache entry is more recent than disk */
  137.  
  138. #define BOOT_BLOCK  0        /* block number of boot block */
  139. #define SUPER_BLOCK 1        /* block number of super block */
  140. #define ROOT_INODE  (mino_t)1    /* inode number for root directory */
  141.  
  142.  
  143. /* Derived sizes */
  144. #define ZONE_NUM_SIZE     (SIZEOF(zone_nr))        /* # bytes in zone nr  */
  145. #define NR_DZONE_NUM     (NR_ZONE_NUMS-2)         /* # zones in inode    */
  146. #define DIR_ENTRY_SIZE     (SIZEOF(dir_struct))           /* # bytes/dir entry   */
  147. #define INODES_PER_BLOCK (BLOCK_SIZE/INODE_SIZE)     /* # inodes/disk blk   */
  148. #define INODE_SIZE     (SIZEOF(d_inode1))         /* bytes in disk inode */
  149. #define NR_DIR_ENTRIES     (BLOCK_SIZE/DIR_ENTRY_SIZE) /* # dir entries/block */
  150. #define NR_INDIRECTS     (BLOCK_SIZE/ZONE_NUM_SIZE)  /* # zones/indir block */
  151. #define NR_DBL         (NR_DZONE_NUM+NR_INDIRECTS) /* 1st zone in dbl ind */
  152. #define INTS_PER_BLOCK     (BLOCK_SIZE/SIZEOF(int))    /* # integers/block    */
  153. #define SUPER_SIZE     (SIZEOF(struct super_block)) /* super_block size    */
  154. #define PIPE_SIZE     (NR_DZONE_NUM*BLOCK_SIZE)   /* pipe size in bytes  */
  155. #define MAX_ZONES (NR_DZONE_NUM+NR_INDIRECTS+(long)NR_INDIRECTS*NR_INDIRECTS)
  156.  
  157. #define NR_ZONE_NUMS2    10
  158. #define NR_DZONE_NUM2    (NR_ZONE_NUMS2-3)
  159. #define ZONE_NUM_SIZE2    (SIZEOF(long))
  160. #define INODES_PER_BLOCK2 (BLOCK_SIZE/INODE_SIZE2)
  161. #define INODE_SIZE2    (SIZEOF(d_inode))
  162. #define NR_INDIRECTS2    (BLOCK_SIZE/ZONE_NUM_SIZE2)
  163. #define NR_DBL2        (NR_DZONE_NUM2+NR_INDIRECTS2)
  164.  
  165.  
  166. #ifndef SEEK_SET
  167. /* lseek() origins */
  168. #define    SEEK_SET    0        /* from beginning of file */
  169. #define    SEEK_CUR    1        /* from current location */
  170. #define    SEEK_END    2        /* from end of file */
  171. #endif
  172.  
  173.  
  174. #ifndef min
  175. #define min(a,b) ((a)>(b) ? (b) : (a))
  176. #endif
  177.  
  178. typedef struct    {
  179.   mino_t s_ninodes;        /* # usable inodes on the minor device */
  180.   zone_nr s_nzones;        /* total device size, including bit maps etc */
  181.   unshort s_imap_blks;        /* # of blocks used by inode bit map */
  182.   unshort s_zmap_blks;        /* # of blocks used by zone bit map */
  183.   zone_nr s_firstdatazn;    /* number of first data zone */
  184.   short int s_log_zsize;    /* log2 of blocks/zone */
  185.   off_t s_max_size;        /* maximum file size on this device */
  186.   short s_magic;        /* magic number to recognize super-blocks */
  187.   short pad;            /* padding */
  188.   long s_zones;            /* long version of s_nzones for v2 */
  189. } super_block;
  190.  
  191. /* super_info contains information about each Minix filesystem */
  192.  
  193. typedef struct  {
  194.     super_block sblk;    /* Actual super block */
  195.     int scsiz;        /* sector size/512 */
  196.     int dev;        /* Device this belongs to */
  197.     long serialno;        /* Serial number of disk (ignored for now)*/
  198.     long ioff;        /* Offset to inode 1 */
  199.     ushort *ibitmap;
  200.     ushort idirty;        /* Set if ibitmap changed after last write */
  201.     ushort *zbitmap;
  202.     ushort zdirty;        /* zbitmap dirty flag */
  203.     long zlast;        /* search start for free zones */
  204.  
  205. /* This lot is filled in as appropriate for each FS type */
  206.  
  207.     char version;        /* 0 for V1, 1 for V2 */
  208.     char big;        /* Use lrecno for this partition */
  209.     unsigned ipb;        /* Inodes per block */
  210.     unsigned zpind;        /* zones per indirection block */
  211.     unsigned dzpi;        /* direct zones per inode */
  212.     unsigned ndbl;        /* first zone number in double indirect block */
  213.     int increment;        /* num of dir_structs per dir entry */
  214. } super_info;
  215.  
  216. /* This is what a directory entry on the disk looks like. Note: we can use
  217.  * a dirty trick to use this same structure for large filenames > 14 chars
  218.  * the idea is to use only a fraction of the total entries , so that if
  219.  * say the filename size is 30 we just use entries 0,2,4,6,8 etc. d_name
  220.  * then occupies all of the next entry. This forces the max filename size
  221.  * to be 2 less than a power of two (and certainly less than 1022), normally
  222.  * 30 should be more than adequate to cover every filename you'll ever see.
  223.  * 62 is for paranoids , but remember the path name limit of 128 characters.
  224.  */
  225.  
  226. typedef struct {        /* directory entry */
  227.   mino_t d_inum;        /* inode number */
  228.   char d_name[MMAX_FNAME(1)];    /* character string */
  229. } dir_struct;
  230.  
  231. typedef struct {        /* disk inode. */
  232.   mode_t i_mode;        /* file type, protection, etc. */
  233.   muid_t i_uid;            /* user id of the file's owner */
  234.   off_t i_size;            /* current file size in bytes */
  235.   time_t i_mtime;        /* when was file data last changed */
  236.   mgid_t i_gid;            /* group number */
  237.   nlink_t i_nlinks;        /* how many links to this file */
  238.   zone_nr i_zone[NR_ZONE_NUMS];    /* block nums for direct, ind, and dbl ind */
  239. } d_inode1;
  240.  
  241. typedef struct {        /* V2.x disk inode */
  242.   ushort i_mode;        /* file type, protection, etc. */
  243.   ushort i_nlinks;        /* how many links to this file. HACK! */
  244.   ushort i_uid;            /* user id of the file's owner. */
  245.   ushort i_gid;            /* group number HACK! */
  246.   off_t i_size;        /* current file size in bytes */
  247.   time_t i_atime;        /* when was file data last accessed */
  248.   time_t i_mtime;        /* when was file data last changed */
  249.   time_t i_ctime;        /* when was inode data last changed */
  250.   long i_zone[NR_ZONE_NUMS2];    /* block nums for direct, ind, and dbl ind */
  251. } d_inode;
  252.  
  253.  
  254.  
  255. typedef
  256.   union {
  257.     char bdata[BLOCK_SIZE];        /* ordinary user data */
  258.     dir_struct bdir[NR_DIR_ENTRIES];    /* directory block */
  259.     zone_nr bind1[NR_INDIRECTS];        /* indirect block */
  260.     long    bind[NR_INDIRECTS2];        /* v2 indirect block */
  261.     d_inode1 binode1[INODES_PER_BLOCK];    /* inode block */
  262.     d_inode binode[INODES_PER_BLOCK2]; /* v2 inode block */
  263.     short bsh[INTS_PER_BLOCK];        /* block full of shorts */
  264.   } bufr;
  265.  
  266. typedef struct {
  267.     bufr    buffer;
  268.     long     block;        /* Block number bufr contains */
  269.     short    drive;        /* Drive of bufr */
  270.     short    status;        /* 0=invalid , 1=valid&clean 2=dirty */
  271. } cache;
  272.  
  273. typedef struct {
  274.     cache *pos,*start,*end;
  275. } cache_control;
  276.  
  277. /* Macros for indirection blocks */
  278.  
  279. #define PIND(vers,tmp,index) \
  280.     ( (vers) ? (tmp->bind[index]) : (tmp->bind1[index]) )
  281. #define IND(vers,temp,index) \
  282.     ( (vers) ? (temp.bind[index]) : (temp.bind1[index]) )
  283.  
  284. #endif
  285.